package 代码随想录_补充题目;

/**
 * @author zx
 * @create 2023-02-10 21:38
 */
public class 按奇偶排序数组II_922 {
    public int[] sortArrayByParityII(int[] nums) {
        int j = 1;
        for(int i = 0;i < nums.length;i += 2){
            if(nums[i] % 2 == 1){//在偶数位找到奇数
                //在奇数位找到一个偶数,交换
                while(nums[j] % 2 != 0 && j < nums.length){
                    j += 2;
                }
                int temp = nums[i];
                nums[i] = nums[j];
                nums[j] = temp;
            }
        }
        return nums;
    }
}
